package offer;

import java.util.Stack;

public class ReversePrint_06 {


    public int[] reversePrint(ListNode head) {
        if(head == null) return new int[0];
        Stack<Integer> stack = new Stack<>();
        while (head != null){
            stack.push(head.val);
            head = head.next;
        }
        int[] res = new int[stack.size()];
        int i = 0;
        while (!stack.isEmpty()){
            res[i] = stack.pop();
            i++;
        }
        return res;
    }

      public class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }
}
